package my.study.c.consul.consumer.app.util;

import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.core5.util.Timeout;

public class MyRequestConfigUtil {

    public static final long CONNECT_TIMEOUT = 5000; //连接超时毫秒数
    public static final long CONNECTION_REQUEST_TIMEOUT = 5000; //请求超时毫秒数
    public static final long RESPONSE_TIMEOUT = 10000; //响应超时毫秒数

    private MyRequestConfigUtil() {
    }

    public static RequestConfig getDefaultConfig() {
        return RequestConfigSingleton.INSTANCE.getInstance();
    }


    private enum RequestConfigSingleton {
        INSTANCE;

        private final RequestConfig requestConfig;

        RequestConfigSingleton() {
            requestConfig = RequestConfig.custom()
                    .setConnectTimeout(Timeout.ofMilliseconds(CONNECT_TIMEOUT))
                    .setConnectionRequestTimeout(Timeout.ofMilliseconds(CONNECTION_REQUEST_TIMEOUT))
                    .setResponseTimeout(Timeout.ofMilliseconds(RESPONSE_TIMEOUT))
                    .build();
        }

        private RequestConfig getInstance() {
            return requestConfig;
        }
    }
}
